// JavaScript Document
$(function () {
    /*city*/
    var def = "", $this;
    $(".selected input").click(function () {
        $(this).next().next(".choose").show()
        $(this).parents(".selected").siblings().find(".choose").hide()
        $("#shade").show();
        if ($this) {
            $this.val(def)
        }
        $this = $(this);
        def = $(this).val();
        $(this).val("")
    })
    $(".selected .choose a").on('click', function () {
        def = $(this).text()
        $this.val(def)
        $this.next("input[type=hidden]").val($(this).attr("valuea"))
        $(".selected .choose").hide()
        $("#shade").hide();
    })
    $("#shade").on('click', function () {
        $(".selected .choose").hide()
        $this.val(def)
        $(this).hide()
    })

    //项目图片切换开始
    /*pictuerLeftTextRight*/
    $('.pictuerLeftTextRight').each(function (index, element) {
        var num = 0;
        var timer = setInterval(function () {
            if (num > 2) {
                num = 0;
                $('.pictuerLeftTextRight').eq(index).find('img').eq(num).addClass('Current').siblings().removeClass('Current');
                $('.pictuerLeftTextRight').eq(index).find('li').eq(num).addClass('current').siblings().removeClass('current');
            } else {
                num++;
                $('.pictuerLeftTextRight').eq(index).find('img').eq(num).addClass('Current').siblings().removeClass('Current');
                $('.pictuerLeftTextRight').eq(index).find('li').eq(num).addClass('current').siblings().removeClass('current');
            }

        }, 8000);
        $('.pictuerLeftTextRight').eq(index).find('li').click(function (e) {
            num = $(this).index();
            $('.pictuerLeftTextRight').eq(index).find('img').eq(num).addClass('Current').siblings().removeClass('Current');
            $(this).addClass('current').siblings().removeClass('current');
        });
    });


    //项目图片切结束


    $('.threePictureShow').css('display', 'none');
//        var flag=true;
//        $('.clickMore').on('click',function(){
//            if(flag){
//                $('.threePictureShow').css('display','block');
//            }else{
//                $('.threePictureShow').css('display','none');
//            }
//            flag=!flag;
//        })


    $('.DescribleOfPicture').hide();
    $('.threePicture ul li').hover(function (e) {
        $(this).find('.DescribleOfPicture').stop().show();
    }, function () {
        $(this).find('.DescribleOfPicture').stop().hide();
    });
})


function showMore(guid, index) {
    $('.threePictureShow').css('display', 'block');
    $.ajax({
        url: "/front/houseBase/showType/" + guid,
        success: function (data) {
            $("#buildingType" + index).html(data);
//                    $('.threePictureShow').css('display','none');
//                    $('.DescribleOfPicture').hide();
            $('.threePicture ul li').hover(function (e) {
                $(this).find('.DescribleOfPicture').stop().show();
            }, function () {
                $(this).find('.DescribleOfPicture').stop().hide();
            });
        }
    });
}


function showMore(guid, index) {
    $.ajax({
        url: "/front/houseBase/showType/" + guid,
        type: 'get',
        dataType: 'json',
        success: function (data) {
//            $("#buildingType" + index).html(data);

            var css = $("#threePictureShow" + index).css("display");
            if (css == "block") {
                $("#threePictureShow" + index).hide();
                $("#threePictureShow" + index).css("display", "none");

            } else if (css == "none") {
                $("#threePictureShow" + index).show();
                $("#threePictureShow" + index).css("display", "block");
            }

            $('.DescribleOfPicture').hide();
            $('.threePicture ul li').hover(function (e) {
                $(this).find('.DescribleOfPicture').stop().show();
            }, function () {
                $(this).find('.DescribleOfPicture').stop().hide();
            });
        }
    });
}

//导航滚动栏
function search() {
    /*
     according url to load data
     */
    var url = window.location.pathname
    var productType = url.split("/")[4];
    var place = $("#place_id").next("input[type=hidden]").val();
    var price = $("#price_id").next("input[type=hidden]").val();
    var type = $("#type_id").next("input[type=hidden]").val();
    $("#houseBaseData").load("/front/houseBase/search", {
        area: place,
        price: price,
        theme: type,
        productType: productType
    });
}
$("img.lazy").lazyload({threshold: 200});
$(".unitMapImg").each(function () {
    var imgLen = $(this).find("img").length;
    if (imgLen > 3) {
        var banner = $(this), bannerPage = 0;
        banner.css({transition: "all 1000ms ease", transform: "translate3d(-" + bannerPage * 430 + "px, 0px, 0px)"});
        banner.css({
            webkitTtransition: "all 1000ms ease",
            webkitTtransform: "translate3d(-" + bannerPage * 430 + "px, 0px, 0px)"
        });
        banner.find("li:eq(0)").css({display: "block"});
        $(this).parent().find(".fa").show().on('click', function () {
            if ($(this).hasClass("fa-angle-left")) {
                if (bannerPage != 0) {
                    bannerPage -= 1
                }
            } else {
                if (parseInt(imgLen / 3) > bannerPage) {
                    bannerPage += 1
                }
            }
            if (supportCss3("transform")) {
                banner.css({transform: "translate3d(-" + bannerPage * 430 + "px, 0px, 0px)"});
                banner.css({webkitTransform: "translate3d(-" + bannerPage * 430 + "px, 0px, 0px)"});
                banner.css({msTransform: "translate(-" + bannerPage * 430 + "px, 0px)"});
            } else {
                banner.animate({
                    left: -bannerPage * 430 + "px"
                }, 1000)
            }
        })
    }
})
function supportCss3(style) {
    var prefix = ['webkit', 'Moz', 'ms', 'o'],
        i,
        humpString = [],
        htmlStyle = document.documentElement.style,
        _toHumb = function (string) {
            return string.replace(/-(\w)/g, function ($0, $1) {
                return $1.toUpperCase();
            });
        };

    for (i in prefix)
        humpString.push(_toHumb(prefix[i] + '-' + style));

    humpString.push(_toHumb(style));

    for (i in humpString)
        if (humpString[i] in htmlStyle) return true;

    return false;
}

jQuery("#sildePic").slide({mainCell: ".picbody", effect: "leftLoop", vis: 3, scroll: 1});
$("#simg img").click(function (event) {
    var s = $(this).attr('src');
    $("#bigimg").attr('src', s);
});
$(function () {
    getUserInfo();
    $('.cnInUl ul li').click(function (e) {
        $(this).addClass('current').siblings().removeClass('current');
    });
    /*nameDetail*/
    $('.nameDetail').css('display', 'non14e');
    $('.personName').hover(function (e) {
        $('.nameDetail').css('display', 'block');
    }, function () {
        $('.nameDetail').css('display', 'none');
    });
})
$("#selectBox .selectItem .select").click(function (event) {
    $(this).find('.dropmenu').toggle();
});
$("#selectBox .selectItem .select .dropmenu li").click(function (event) {
    var text = $(this).html();
    var txtojb = $(this).parent().siblings('.text');
    txtojb.html(text);
    rentSearch()
});
$("#selectBox .selectItem .select input").change(function () {
    rentSearch()
})
function rentSearch() {
    var area = $("#area").html();
    var week = $("#week").html();
    var price = $("#price").val();
    var themes = $("#themes").html();
    $("#listData").empty();
    $("#listData").load("/rent/search", {area: area, week: week, price: price, themes: themes});
}

function getUserInfo() {
//            location.href="/public/userinfo";
//    $.ajax({
//        url: "/front/user_info/userinfo",
//        success: function (data) {
//            var userName = data.username;
//            $("#userName").html(userName);
//            var imageGuid = data.imageGuid;
//            console.log("Sdf")
//            if (userName != null) {
//                console.log("Sdf")
//                if ($(window).width() == 768) {
//                    $(".loginBtn").show();
//                    $("#noLogin").hide();
//                    $("#userAlert").hide();
//                    console.log("Sdf")
//                } else {
//                    $(".loginBtn").hide();
//                    $("#userAlert").show();
//                    $("#noLogin").hide();
//                    var url = "/public/image/" + imageGuid;
//                    $("#userName_1").html("Hi," + data.username);
//                    $("#userAlert .alertUserName").html(data.username);
//                    $("#userAlert .userIcon img").attr("src", url);
//                    $(".signAndRegister").hide()
//                }
//            } else {
//                $("#userAlert").hide()
//            }
//        }
//    });
}
$(function () {
    var Height = $('.pictuerLeft img').height();
    $('.pictuerLeft').css('height', Height);
})
$(function () {
    var type = $("#type").val();
    if (type == 'introduce') {
        loadContent('message');
    } else if (type == 'model') {
        loadContent('style');
    } else if (type == 'concept') {
        loadContent('idea');
    } else if (type == 'cooperation') {
        loadContent('project');
    } else if (type == 'news') {
        loadContent('news');
    }
})

function loadContent(value) {
    hideNav();
    if (value == "message") {
        $("#d_message").addClass("current");
    } else if (value == "style") {
        $("#d_style").addClass("current");
    } else if (value == "idea") {
        $("#d_idea").addClass("current");
    } else if (value == "project") {
        $("#d_project").addClass("current");
    } else if (value == "news") {
        $("#d_news").addClass("current");
    }
}

function hideNav() {
    $("#d_message").removeClass("current");
    $("#d_style").removeClass("current");
    $("#d_idea").removeClass("current");
    $("#d_project").removeClass("current");
    $("#d_news").removeClass("current");
}
function findCity() {
    var provinceId = $("#province").val();
    $("#city").empty();
    $.ajax({
        url: "/front/user_info/findCity",
        type: "POST",
        data: "provinceId=" + provinceId,
        dataType: "json",
        success: function (data) {
            $("#city").html(data);
        }
    });
}

function findDistrict() {
    var cityId = $("#city").val();
    $("#district").empty();
    $.ajax({
        url: "/front/user_info/findDistrict",
        type: "POST",
        data: "cityId=" + cityId,
        dataType: "json",
        success: function (data) {
            $("#district").html(data);
        }
    });
}

function validUsername() {
    var username = $("#username").val();
    $.ajax({
        url: '/valid/userinfo/username',
        type: 'post',
        data: {username: username},
        success: function (data) {
            if (data) {
                $('#username').next("span").html("");
                $(".save").removeAttr("disabled");
            } else {
                $('#username').next("span").html("用户名已被使用!");
                $(".save").attr("disabled", "true");
            }
        }
    })
}

function validRealName() {
    var realName = $('#realName').val();
    $.ajax({
        url: '/valid/userinfo/realname',
        type: 'post',
        data: {realName: realName},
        success: function (data) {
            if (data) {
                $('#realName').next("span").html("");
                $(".save").removeAttr("disabled");
            } else {
                $('#realName').next("span").html("不能有非法字符!");
                $(".save").attr("disabled", "true");
            }
        }
    })
}

function validEmail() {
    var email = $('#email').val();
    $.ajax({
        url: '/valid/userinfo/email',
        type: 'post',
        data: {email: email},
        success: function (data) {
            if (data) {
                $('#email').next('span').html('');
                $(".save").removeAttr("disabled");
            } else {
                $('#email').next('span').html('邮箱不正确!');
                $(".save").attr("disabled", "true");
            }
        }
    })
}

function validIdCard() {
    var idCard = $('#IDCard').val();
    $.ajax({
        url: '/valid/userinfo/idcard',
        type: 'post',
        data: {idCard: idCard},

        success: function (data) {
            if (data) {
                $('#IDCard').next('span').html('');
                $(".save").removeAttr("disabled");
            } else {
                $('#IDCard').next('span').html('身份证不正确!');
                $(".save").attr("disabled", "true");
            }
        }
    })
}
$(".faqContent .answerList li").on('click', function () {
    if ($(this).find("div").is(":hidden")) {
        $(this).find("div").slideDown();
        $(this).find("i").addClass("active")
    } else {
        $(this).find("div").slideUp()
        $(this).find("i").removeClass("active")
    }
})
$(function () {
    $("#submit").attr("disabled", "true");
    $('form').submit(function () {
        validRealName();
        validIdCard();
        var province = $("#province").val();
        var city = $("#city").val();
        var district = $("#district").val();
        var area = $("#area").val();
        if ("noselect" == province || "noselect" == city || "noselect" == district || "noselect" == area) {
            $("#area").next("span").html("请完善联系地址!");
            return false;
        } else {
            $("#area").next("span").html("");
        }
    })
});

function findCity() {
    var provinceId = $("#province").val();
    if (provinceId != "noselect") {
        $("#city").empty();
        $.ajax({
            url: "/front/user_info/findCity",
            type: "POST",
            data: "provinceId=" + provinceId,
            dataType: "json",
            success: function (data) {
                $("#city").html(data);
            }
        });
    }
}

function findDistrict() {
    var cityId = $("#city").val();
    if (cityId != "noselect") {
        $("#district").empty();
        $.ajax({
            url: "/front/user_info/findDistrict",
            type: "POST",
            data: "cityId=" + cityId,
            dataType: "json",
            success: function (data) {
                $("#district").html(data);
            }
        });
    }
}

function validRealName() {
    var realName = $('#realName').val();
    $.ajax({
        url: '/valid/userinfo/realname',
        type: 'post',
        data: {realName: realName},
        success: function (data) {
            if (data) {
                $('#realName').next("span").html("");
                $("#submit").removeAttr("disabled");
            } else {
                $('#realName').next("span").html("不能有非法字符!");
                $("#submit").attr("disabled", "true");
            }
        }
    })
}

function validIdCard() {
    var idCard = $('#IDCard').val();
    $.ajax({
        url: '/valid/userinfo/idcard',
        type: 'post',
        data: {idCard: idCard},
        success: function (data) {
            if (data) {
                $('#IDCard').next('span').html('');
                $("#submit").removeAttr("disabled");
            } else {
                $('#IDCard').next('span').html('身份证不正确!');
                $("#submit").attr("disabled", "true");
            }
        }
    })
}
function aboutNav($this) {
    $(".aboutRight .aboutText").hide()
    $(".aboutRight .aboutDiv" + $this).show();
}
function getUserInfo() {
//            location.href="/public/userinfo";
    $.ajax({
        url: "/front/user_info/userinfo",
        success: function (data) {
            var userName = data.username;
            var imageGuid = data.imageGuid;
            if (userName != null) {
                if ($(window).width() == 768) {
                    $(".loginBtn").show();
                    $("#noLogin").hide();
                    $("#userAlert").hide();
                    $(".noLoginBtn").hide();
                } else {
                    $(".nameDetail .signAndRegister").hide();
                    $("#noLogin").hide();
                    $("#userAlert").show()
                    $(".noLoginBtn").hide();
                    var url = "/public/image/" + imageGuid;
                    $("#userName_1").html("Hi," + data.username);
                    $(".nameDetail .nameTop .alertUserName").html(data.username);
                    $(".nameDetail .nameTop img").attr("src", url);
                }
            }
        }
    });
}
function userDetails() {
    location.href = "/front/user_info/form";
}
//changeTab 开始
$('.changeTab li').click(function (e) {
    $('.devideText01').eq(($(this).index() - 1)).addClass('TextCurrent').siblings().removeClass('TextCurrent');
    $(this).addClass('TimeCurrent').siblings().removeClass('TimeCurrent');
    var price = $(this).find(".weekPrice").html()
    $(".projectTotal .PriceAll").html('总价：' + price);
});
var price = $('.weekPrice').eq(0).html()
$(".projectTotal .PriceAll").html('总价：' + price);
function toOrder() {
    var guid = $(".TimeCurrent").find("span").html();
    location.href = "/order/form/" + guid;
}
$("#simg img").on('click', function () {
    $("#bigimg").attr("src", $(this).attr("src"))
})
$("#dec4 .decimg").hover(function () {
    var s = $(this).attr("data-img");
    $(this).attr("data-img", $(this).attr("src"));
    $(this).attr("src", s);
}, function () {
    var s = $(this).attr("data-img");
    $(this).attr("data-img", $(this).attr("src"));
    $(this).attr("src", s);
})